<?php

namespace fztadmin\modules\ajax\controllers;

use common\models\db\Custom;
use yii\web\Controller;
use yii\web\Response;

class CustController extends Controller
{
    public function actionGetCustomNoSel($q = null, $json_data= null)
    {
        \Yii::$app->response->format = Response::FORMAT_JSON;
        $query = Custom::find()->where(['is not', 'plat_cust_no', null]);
        $out = ['results' => [['id' => '', 'text' => '']]];
        if ($q) {
            $query->andWhere(['or', ['like', 'cust_name', $q], ['mobile_no' => $q], ['id_no' => $q]]);
        }
        $data = $query->limit(10)->all();
        $results = [];
        foreach ($data as $k => $v) {
            $results[] = ['id' => $v['plat_cust_no'], 'text' => "{$v['cust_name']} {$v['mobile_no']} {$v['id_no']}"];
        }
        $out['results'] = $results;
        return $out;
    }
}